package com.whmskj.xjlhsc.pc.productionreport.task.dailyReport;

import com.whmskj.xjlhsc.pc.productionreport.report.pojo.DayReportsVO;
import com.whmskj.xjlhsc.pc.productionreport.report.service.imp.DayReportServiceImpl;
import com.whmskj.xjlhsc.pc.productionreport.task.mapper.ProductionMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/**
 * @author jiaruchun
 * @date 2025-09-22 20:31
 */
@Slf4j
@Component
@EnableScheduling
public class dailyReportTask {

    @Autowired
    private DayReportServiceImpl dayReportServiceImpl;
    @Autowired
    private ProductionMapper productionMapper;

    /*前纺日报*/
    //每天早上10点10分执行
    @Scheduled(cron = "0 10 10 * * ?")
    //每隔5秒执行
//    @Scheduled(cron = "0/5 * * * * ?")
    public void dayReportTask(){
        List<DayReportsVO> qianfang = dayReportServiceImpl.getDayReport("前纺");
        List<DayReportsVO> xiSha = dayReportServiceImpl.getDayReport("细纱");
        List<DayReportsVO> luoTong = dayReportServiceImpl.getDayReport("络筒");
        log.info("每日生产报表任务执行完成");
        if (productionMapper.getDayProductionDataByDateLuo(LocalDate.now().minusDays(1).toString()) == 0) {
            productionMapper.insertLuoTongDayReport(luoTong);
        }
        if (productionMapper.getDayProductionDataByDateXi(LocalDate.now().minusDays(1).toString()) == 0) {
            productionMapper.insertXShaDayReport(xiSha);
        }
        if (productionMapper.getDayProductionDataByDateQian(LocalDate.now().minusDays(1).toString()) == 0) {
            productionMapper.insertQianfangDayReport(qianfang);
        }
    }
}
